package com.litch.mvpdemo.view.activitys;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.litch.mvpdemo.R;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created by Administrator on 2016/7/11.
 */
public class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setLayout();
        initView();
    }
    private void initView(){
        Class clazz = this.getClass();
        Method[] methods = clazz.getDeclaredMethods();
        for(Method m : methods){
            if(m.isAnnotationPresent(InitView.class)){
                m.setAccessible(true);
                try {
                    m.invoke(this);
                    break;
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    private void setLayout(){
        setContentView(R.layout.activity_main);
        Class clazz = this.getClass();
        if(clazz.isAnnotationPresent(AppActivity.class)){
            AppActivity appActivity = (AppActivity) clazz.getAnnotation(AppActivity.class);
            int layoutId = appActivity.layoutId();
            setContentView(layoutId);
        }
    }
}
